#!/usr/bin/perl

use strict;
use warnings;

# data memeber declaration
my ($dir,
	$dir_in,
	@filelist,
	$i,
	$path_abs,
	$pattern_base,
	$pattern_final);

print "\n";
print "-------------------------------------\n";
print "Pattern Enforcer [build dt 4-6-2012]\n";
print "-------------------------------------\n";
print "\n";

# get input from user
print "Type in the absolute path: ";
chomp($dir_in = <STDIN>);
print "Type in the proposed pattern: ";
chomp($pattern_base = <STDIN>);

# open target directory
opendir $dir, $dir_in or die $!;

# retrieve filenames into an array
@filelist = readdir $dir;

# rename files
for($i = 2; $filelist[$i]; $i++) {
	$path_abs = $dir_in.("\\").$filelist[$i];
	$pattern_final = $pattern_base.($i - 1).("\.jpg");
	
	# for debugging purpose
	# print "filename[$i]: $filelist[$i]\n";
	# print "path_abs: $path_abs\n";
	# print "pattern_final: $pattern_final\n\n";
	
	system("rename \"$path_abs\" $pattern_final");
}

close $dir;